package com.servlet.employee;

import com.bean.Employee;
import com.service.AdminService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/admin/listEmployeeByDept")
public class ListEmployeeByDeptServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AdminService adminService=new AdminService();
        String deptid=req.getParameter("deptid");
        if (deptid.length() != 2||!adminService.judgeContainsStr(deptid)){
            req.setAttribute("Message", "部门号不满足要求，查找失败！");
            req.getRequestDispatcher("admingetfail.jsp").forward(req, resp);
            return;
        }
        if (!adminService.getDept(deptid)){
            req.setAttribute("Message", "部门不存在，查找失败！");
            req.getRequestDispatcher("admingetfail.jsp").forward(req, resp);
            return;
        }
        List<Employee> employees = adminService.getEmployeeListByDept(deptid);
        req.setAttribute("employees",employees);
        req.getRequestDispatcher("adminsearchuser.jsp").forward(req, resp);
    }
}
